﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI;
using YArchitech.Revit;

namespace YArchitech.HVAC
{
	public class XmlInfo
	{
		public static bool ScheduleIsExist(string strName)
		{
			return XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/DaySchedules/DaySchedule[@name='" + strName + "']") != null;
		}

		public static void loadWallParams()
		{
			XmlInfo.docWallParams = new XmlDocument();
			XmlInfo.docWallParams.Load(WinFormTools.hyDataPath() + "WallParams.xml");
		}

		public static void saveWallParams()
		{
			XmlInfo.docWallParams.Save(WinFormTools.hyDataPath() + "WallParams.xml");
		}

		public static void CreateProjectWallParams(string sPath)
		{
			if (XmlInfo.docWallParams.SelectSingleNode("Projects/Params[@Project='" + sPath + "']") == null)
			{
				XmlElement xmlElement = XmlInfo.docWallParams.CreateElement("Params");
				xmlElement.SetAttribute("Project", sPath);
				XmlInfo.docWallParams.DocumentElement.AppendChild(xmlElement);
			}
		}

		public static string GetWallParam(string sPath, string wallType, string func, string materId, string pName)
		{
			XmlNode xmlNode = XmlInfo.docWallParams.SelectSingleNode(string.Concat(new string[]
			{
				"Projects/Params[@Project='",
				sPath,
				"']/Param[@WallType='",
				wallType,
				"'][@Func='",
				func,
				"'][@MaterId='",
				materId,
				"']"
			}));
			if (xmlNode == null)
			{
				XmlElement xmlElement = XmlInfo.docWallParams.CreateElement("Param");
				xmlElement.SetAttribute("WallType", wallType);
				xmlElement.SetAttribute("Func", func);
				xmlElement.SetAttribute("MaterId", materId);
				xmlElement.SetAttribute("DRXS", "1");
				xmlElement.SetAttribute("XZXS", "1");
				XmlInfo.docWallParams.SelectSingleNode("Projects/Params[@Project='" + sPath + "']").AppendChild(xmlElement);
				return "1";
			}
			return xmlNode.Attributes[pName].Value;
		}

		public static void ModifyWallParam(string sPath, string wallType, string func, string materId, string pName, string sVal)
		{
			XmlNode xmlNode = XmlInfo.docWallParams.SelectSingleNode(string.Concat(new string[]
			{
				"Projects/Params[@Project='",
				sPath,
				"']/Param[@WallType='",
				wallType,
				"'][@Func='",
				func,
				"'][@MaterId='",
				materId,
				"']"
			}));
			if (xmlNode == null)
			{
				XmlElement xmlElement = XmlInfo.docWallParams.CreateElement("Param");
				xmlElement.SetAttribute("WallType", wallType);
				xmlElement.SetAttribute("Func", func);
				xmlElement.SetAttribute("MaterId", materId);
				xmlElement.SetAttribute("DRXS", "1");
				xmlElement.SetAttribute("XZXS", "1");
				xmlElement.SetAttribute(pName, sVal);
				XmlInfo.docWallParams.SelectSingleNode("Projects/Params[@Project='" + sPath + "']").AppendChild(xmlElement);
				return;
			}
			xmlNode.Attributes[pName].Value = sVal;
		}

        public static void GetAttrVal(string strAttrName, System.Windows.Forms.ComboBox comBox)
		{
			string a;
			if (strAttrName.Contains("标高"))
			{
				a = "标高";
			}
			else
			{
				a = strAttrName;
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlAttrVal);
			XmlNodeList xmlNodeList = null;
			if (a == "标高")
			{
				xmlNodeList = xmlDocument.SelectSingleNode("Elements/Level").ChildNodes;
			}
			if (xmlNodeList != null)
			{
				WinFormTools.BindValueComboBox(comBox, xmlNodeList);
			}
		}

		public static void LoadAttrVal(ExternalCommandData revit)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlAttrVal);
			xmlDocument.DocumentElement.RemoveAll();
			ICollection<Element> allLevelVal = RevitTools.GetAllLevelVal(revit);
			XmlElement xmlElement = xmlDocument.CreateElement("Level");
			for (int i = 0; i < allLevelVal.Count; i++)
			{
				Element element = allLevelVal.ElementAt(i);
				XmlElement xmlElement2 = xmlDocument.CreateElement("LevelVal");
				xmlElement2.InnerText = element.Name;
				xmlElement.AppendChild(xmlElement2);
			}
			xmlDocument.DocumentElement.AppendChild(xmlElement);
			XmlInfo.xmlAttrVal = xmlDocument.InnerXml;
		}

		public static bool IsSpaceKeyUsed(string strKey)
		{
			return XmlInfo.docSpaceKeyword.SelectSingleNode("SpaceKeywords/SpaceKeyword[@KeyName='" + strKey + "']") != null;
		}

		public static XmlNode GetKeyById(string keyId)
		{
			return XmlInfo.docSpaceKeyword.SelectSingleNode("SpaceKeywords/SpaceKeyword[@KID='" + keyId + "']");
		}

		public static XmlNodeList GetScheduleByName(string ScheduleName)
		{
			return XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/DaySchedules/DaySchedule[@name='" + ScheduleName + "']").ChildNodes;
		}

		public static XmlNodeList GetSpaceInfoValue()
		{
			return XmlInfo.docSpaceInfo.SelectSingleNode("SpaceTypes/SpaceType").ChildNodes;
		}

		public static void ChangeSpaceInfo(string pName, string pValue)
		{
			XmlNode xmlNode = XmlInfo.docSpaceInfo.SelectSingleNode("SpaceTypes/SpaceType/Param[@name='" + pName + "']");
			xmlNode.Attributes["value"].Value = pValue;
			if (xmlNode.Attributes["dayScheduleIdRef"] != null)
			{
				xmlNode.Attributes["dayScheduleIdRef"].Value = XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/DaySchedules/DaySchedule[@name='" + pValue + "']").Attributes["id"].Value;
			}
		}

		public static string ConvertSpaceInfoValue(string pName, string pValue)
		{
			string result;
			if (pName.Contains("温度") || pName.Contains("湿度"))
			{
				result = (Convert.ToDouble(pValue) - 273.15).ToString();
			}
			else
			{
				result = pValue;
			}
			return result;
		}

		public static void SetSpaceInfoValue(ExternalCommandData cmdData, Space space)
		{
			foreach (object obj in XmlInfo.docSpaceInfo.SelectNodes("SpaceTypes/SpaceType[@name='默认']/Param"))
			{
				XmlNode xmlNode = (XmlNode)obj;
				Parameter parameter = space.GetParameter(xmlNode.Attributes["name"].Value);
				xmlNode.Attributes["value"].Value = XmlInfo.ConvertSpaceInfoValue(xmlNode.Attributes["name"].Value, RevitTools.GetParamVal(cmdData.Application.ActiveUIDocument.Document, parameter));
			}
		}

		public static string GetSpaceInfoValue(string sName)
		{
			return XmlInfo.docSpaceInfo.SelectSingleNode("SpaceTypes/SpaceType[@name='默认']/Param[@name='" + sName + "']").Attributes["value"].Value;
		}

		public static string GetSpaceInfoValue(string sName, Space space, ExternalCommandData cmdData)
		{
			Parameter parameter = space.GetParameter(sName);
			return XmlInfo.ConvertSpaceInfoValue(sName, RevitTools.GetParamVal(cmdData.Application.ActiveUIDocument.Document, parameter));
		}

		public static void loadSpaceInfo()
		{
			XmlInfo.docSpaceInfo = new XmlDocument();
			XmlInfo.docSpaceInfo.InnerXml = XmlInfo.docSpaceType.InnerXml;
			foreach (object obj in XmlInfo.docSpaceInfo.SelectNodes("SpaceTypes/SpaceType"))
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.Attributes["name"].Value != "默认")
				{
					xmlNode.ParentNode.RemoveChild(xmlNode);
				}
			}
		}

		public static void loadSpaceKeyword()
		{
			XmlInfo.docSpaceKeyword = new XmlDocument();
			XmlInfo.docSpaceKeyword.Load(WinFormTools.hyGetSpaceKeywordPath());
		}

		public static void saveSpaceKeyword()
		{
			XmlInfo.docSpaceKeyword.Save(WinFormTools.hyGetSpaceKeywordPath());
		}

		public static void loadSpaceType()
		{
			XmlInfo.docSpaceType = new XmlDocument();
			XmlInfo.docSpaceType.Load(WinFormTools.hyGetSpaceTypesPath());
			XmlInfo.docSpaceTypeTmp = new XmlDocument();
			XmlInfo.docSpaceTypeTmp.Load(WinFormTools.hyGetSpaceTypesPath());
		}

		public static void saveSpaceType()
		{
			XmlInfo.docSpaceType.Save(WinFormTools.hyGetSpaceTypesPath());
		}

		public static bool spaceNameIsUse(string typeName)
		{
			return XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/SpaceType[@name='" + typeName + "']") != null;
		}

		public static bool scheduleNameIsUse(string typeName)
		{
			return XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/DaySchedules/DaySchedule[@name='" + typeName + "']") != null;
		}

		public static void ChangeSpaceType(string typeName, string pName, string pValue)
		{
			XmlNode xmlNode = XmlInfo.docSpaceType.SelectSingleNode(string.Concat(new string[]
			{
				"SpaceTypes/SpaceType[@name='",
				typeName,
				"']/Param[@name='",
				pName,
				"']"
			}));
			xmlNode.Attributes["value"].Value = pValue;
			if (xmlNode.Attributes["dayScheduleIdRef"] != null)
			{
				xmlNode.Attributes["dayScheduleIdRef"].Value = XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/DaySchedules/DaySchedule[@name='" + pValue + "']").Attributes["id"].Value;
			}
		}

		public static XmlNodeList GetSpaceKeyword()
		{
			return XmlInfo.docSpaceKeyword.DocumentElement.ChildNodes;
		}

		public static void DeleteSpaceKeyword(string KID)
		{
			XmlNode xmlNode = XmlInfo.docSpaceKeyword.SelectSingleNode("SpaceKeywords/SpaceKeyword[@KID='" + KID + "']");
			xmlNode.ParentNode.RemoveChild(xmlNode);
		}

		public static void ChangeSpaceKeyword(string KID, string KeyName, string TypeName)
		{
			XmlNode xmlNode = XmlInfo.docSpaceKeyword.SelectSingleNode("SpaceKeywords/SpaceKeyword[@KID='" + KID + "']");
			xmlNode.Attributes["KeyName"].Value = KeyName;
			xmlNode.Attributes["TypeName"].Value = TypeName;
		}

		public static string GetKeyNameById(string KID)
		{
			XmlNode xmlNode = XmlInfo.docSpaceKeyword.SelectSingleNode("SpaceKeywords/SpaceKeyword[@KID='" + KID + "']");
			if (xmlNode != null)
			{
				return xmlNode.Attributes["KeyName"].Value;
			}
			return "";
		}

		public static XmlNodeList GetSpaceTypes()
		{
			return XmlInfo.docSpaceType.SelectNodes("SpaceTypes/SpaceType");
		}

		public static XmlNodeList GetDaySchedules()
		{
			return XmlInfo.docSpaceType.SelectNodes("SpaceTypes/DaySchedules/DaySchedule");
		}

		public static string GetSpaceTypeNameByKey(string sKey)
		{
			sKey.Replace("?", "[0-9]*[0-9]");
			XmlNodeList spaceKeyword = XmlInfo.GetSpaceKeyword();
			ArrayList arrayList = new ArrayList();
			foreach (object obj in spaceKeyword)
			{
				XmlNode xmlNode = (XmlNode)obj;
				arrayList.Add(xmlNode.Attributes["KeyName"].Value);
			}
			IEnumerator enumerator2 = arrayList.GetEnumerator();
			string text = "默认";
			while (enumerator2.MoveNext())
			{
				object obj2 = enumerator2.Current;
				string text2 = (string)obj2;
				if (new Regex(text2).IsMatch(sKey))
				{
					if (text == "默认")
					{
						text = text2;
					}
					else if (text2.IndexOf(text) >= 0)
					{
						text = text2;
					}
				}
			}
			string result = "默认";
			foreach (object obj3 in spaceKeyword)
			{
				XmlNode xmlNode2 = (XmlNode)obj3;
				if (xmlNode2.Attributes["KeyName"].Value == text)
				{
					result = xmlNode2.Attributes["TypeName"].Value;
				}
			}
			return result;
		}

		public static XmlNodeList GetSpaceTypeValue(string sName)
		{
			if (sName == "")
			{
				return null;
			}
			if (XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/SpaceType[@name='" + sName + "']") == null)
			{
				return null;
			}
			return XmlInfo.docSpaceType.SelectSingleNode("SpaceTypes/SpaceType[@name='" + sName + "']").ChildNodes;
		}

		public static string GetSpaceTypeValue(string sTypeName, string sName)
		{
			return XmlInfo.docSpaceType.SelectSingleNode(string.Concat(new string[]
			{
				"SpaceTypes/SpaceType[@name='",
				sTypeName,
				"']/Param[@name='",
				sName,
				"']"
			})).Attributes["value"].Value;
		}

		public static string GetSpaceTypeSchedule(string sTypeName, string sName)
		{
			return XmlInfo.docSpaceType.SelectSingleNode(string.Concat(new string[]
			{
				"SpaceTypes/SpaceType[@name='",
				sTypeName,
				"']/Param[@name='",
				sName,
				"']"
			})).Attributes["dayScheduleIdRef"].Value;
		}

		public static bool SelNameIsExist(string sName)
		{
			return XmlInfo.hyXmlDoc.SelectSingleNode("SelSets/SelSet[@Text='" + sName + "']") != null;
		}

		public static void UpdateFilter(XmlNode nodeSelSet, XmlNode nodeFilters, string name, string valid, string attr, string value, string formula)
		{
			try
			{
				XmlElement xmlElement = XmlInfo.hyXmlDoc.CreateElement("Filter");
				xmlElement.SetAttribute("Name", name);
				xmlElement.SetAttribute("Valid", valid);
				xmlElement.SetAttribute("Attr", attr);
				xmlElement.SetAttribute("Value", value);
				xmlElement.SetAttribute("Formula", formula);
				nodeFilters.AppendChild(xmlElement);
				nodeSelSet.AppendChild(nodeFilters);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}

		public static void UpdateFilter(XmlNode nodeSelSet, XmlElement nodeFilters, string name, string valid, string attr, string value, string formula)
		{
			try
			{
				XmlElement xmlElement = XmlInfo.hyXmlDoc.CreateElement("Filter");
				xmlElement.SetAttribute("Name", name);
				xmlElement.SetAttribute("Valid", valid);
				xmlElement.SetAttribute("Attr", attr);
				xmlElement.SetAttribute("Value", value);
				xmlElement.SetAttribute("Formula", formula);
				nodeFilters.AppendChild(xmlElement);
				nodeSelSet.AppendChild(nodeFilters);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}

		public static void hyLoadXml()
		{
			XmlInfo.hyXmlDoc.Load(XmlInfo.hyGetPath());
		}

		public static void hySaveXml()
		{
			XmlInfo.hyXmlDoc.Save(XmlInfo.hyGetPath());
		}

		public static string hyGetPath()
		{
			return Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) + "\\Data\\SelSets.xml";
		}

		public static void AddSelSet(string sPath, string sTitle, string selSetXml)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlSelSets);
			XmlNode xmlNode = xmlDocument.SelectSingleNode(string.Concat(new string[]
			{
				"SelSets/SelSet[@Title='",
				sTitle,
				"'][@Path='",
				sPath,
				"']"
			}));
			if (xmlNode != null)
			{
				xmlNode.InnerText = CEncrypt.DesEncrypt(selSetXml);
			}
			else
			{
				XmlElement xmlElement = xmlDocument.CreateElement("SelSet");
				xmlElement.SetAttribute("Title", sTitle);
				xmlElement.SetAttribute("Path", sPath);
				xmlElement.InnerText = CEncrypt.DesEncrypt(selSetXml);
				xmlDocument.DocumentElement.AppendChild(xmlElement);
			}
			XmlInfo.xmlSelSets = xmlDocument.InnerXml;
		}

		public static void DeleteSelSet(string sPath, string sTitle)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlSelSets);
			XmlNode xmlNode = xmlDocument.SelectSingleNode(string.Concat(new string[]
			{
				"SelSets/SelSet[@Title='",
				sTitle,
				"'][@Path='",
				sPath,
				"']"
			}));
			if (xmlNode != null)
			{
				xmlNode.ParentNode.RemoveChild(xmlNode);
				XmlInfo.xmlSelSets = xmlDocument.InnerXml;
			}
		}

		public static string GetSelSet(string sPath, string sTitle)
		{
			string result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements></Elements>";
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlSelSets);
			XmlNode xmlNode = xmlDocument.SelectSingleNode(string.Concat(new string[]
			{
				"SelSets/SelSet[@Title='",
				sTitle,
				"'][@Path='",
				sPath,
				"']"
			}));
			if (xmlNode != null)
			{
				result = CEncrypt.DesDecrypt(xmlNode.InnerText);
			}
			return result;
		}

		public static string GetSelSetStr(string filePath, string sPath, string sTitle)
		{
			string result;
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(filePath);
				XmlNode xmlNode = xmlDocument.SelectSingleNode(string.Concat(new string[]
				{
					"SelSets/SelSet[@Title='",
					sTitle,
					"'][@Path='",
					sPath,
					"']"
				}));
				if (xmlNode != null)
				{
					result = CEncrypt.DesDecrypt(xmlNode.InnerText);
				}
				else
				{
					result = null;
				}
			}
			catch (Exception ex)
			{
				ex.ToString();
				result = null;
			}
			return result;
		}

		public static void SetSelSetStr(string filePath, string sPath, string sTitle, string sXml)
		{
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(filePath);
				XmlNode xmlNode = xmlDocument.SelectSingleNode(string.Concat(new string[]
				{
					"SelSets/SelSet[@Title='",
					sTitle,
					"'][@Path='",
					sPath,
					"']"
				}));
				if (xmlNode != null)
				{
					xmlNode.InnerText = CEncrypt.DesEncrypt(sXml);
				}
				else
				{
					XmlElement xmlElement = xmlDocument.CreateElement("SelSet");
					xmlElement.SetAttribute("Title", sTitle);
					xmlElement.SetAttribute("Path", sPath);
					xmlElement.InnerText = CEncrypt.DesEncrypt(sXml);
					xmlDocument.DocumentElement.AppendChild(xmlElement);
				}
				xmlDocument.Save(filePath);
			}
			catch (UnauthorizedAccessException ex)
			{
				ex.ToString();
				MessageBox.Show("非管理员身份运行，数据无法保存。");
			}
			catch (Exception ex2)
			{
				MessageBox.Show(ex2.ToString());
			}
		}

		public static void selDelete(string sPath, string sTitle)
		{
			string selSet = XmlInfo.GetSelSet(sPath, sTitle);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(selSet);
			foreach (object obj in xmlDocument.SelectNodes("Elements/Select"))
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.Attributes["Check"].Value == "true")
				{
					xmlNode.ParentNode.RemoveChild(xmlNode);
				}
			}
			XmlInfo.AddSelSet(sPath, sTitle, xmlDocument.InnerXml);
		}

		public static bool SelIsNull(string sPath, string sTitle)
		{
			string selSet = XmlInfo.GetSelSet(sPath, sTitle);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(selSet);
			return xmlDocument.SelectNodes("Elements/Select").Count == 0;
		}

		public static XmlNode GetSelectSetByName(string selName, string sPath, string sTitle)
		{
			string selSet = XmlInfo.GetSelSet(sPath, sTitle);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(selSet);
			return xmlDocument.SelectSingleNode("Elements/Select[@Name='" + selName + "']");
		}

		public static XmlNodeList GetCheckSelectSet(string sPath, string sTitle)
		{
			string selSet = XmlInfo.GetSelSet(sPath, sTitle);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(selSet);
			return xmlDocument.SelectNodes("Elements/Select[@Check=\"true\"]");
		}

		public static bool LevelFirst()
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlLevelStr);
			return xmlDocument.SelectNodes("Elements/Level").Item(0).Attributes["Check"].Value == "true";
		}

		public static void ChangeFirstLevel(bool b)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlLevelStr);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Elements/Level");
			if (b)
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "true";
			}
			else
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "false";
			}
			XmlInfo.xmlLevelStr = xmlDocument.InnerXml;
		}

		public static void ChangeSelLevel(int row, bool b)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlLevelStr);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Elements/Level");
			if (b)
			{
				xmlNodeList.Item(row).Attributes["Check"].Value = "true";
			}
			else
			{
				xmlNodeList.Item(row).Attributes["Check"].Value = "false";
			}
			foreach (object obj in xmlNodeList)
			{
				((XmlNode)obj).Attributes["Check"].Value = "true";
			}
			XmlInfo.xmlLevelStr = xmlDocument.InnerXml;
		}

		public static bool CateFirst()
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCateStr);
			return xmlDocument.SelectNodes("Elements/Cate").Item(0).Attributes["Check"].Value == "true";
		}

		public static void ChangeFirstCate(bool b)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCateStr);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Elements/Cate");
			if (b)
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "true";
			}
			else
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "false";
			}
			XmlInfo.xmlCateStr = xmlDocument.InnerXml;
		}

		public static void ChangeSelCate(int row, bool b)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCateStr);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Elements/Cate");
			if (b)
			{
				xmlNodeList.Item(row).Attributes["Check"].Value = "true";
			}
			else
			{
				xmlNodeList.Item(row).Attributes["Check"].Value = "false";
			}
			XmlInfo.xmlCateStr = xmlDocument.InnerXml;
		}

		public static void RegForm(string proTitle, string proPath)
		{
			proTitle = CEncrypt.Encrypt(proTitle);
			proPath = CEncrypt.Encrypt(proPath);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlForm);
			XmlElement documentElement = xmlDocument.DocumentElement;
			XmlElement xmlElement = xmlDocument.CreateElement("Form");
			xmlElement.SetAttribute("Title", proTitle);
			xmlElement.SetAttribute("Path", proPath);
			documentElement.AppendChild(xmlElement);
			XmlInfo.xmlForm = xmlDocument.InnerXml;
		}

		public static bool FormIsExist(string proTitle, string proPath)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlForm);
			return xmlDocument.SelectSingleNode(string.Concat(new string[]
			{
				"Forms/Form[@Title='",
				CEncrypt.Encrypt(proTitle),
				"'][@Path='",
				CEncrypt.Encrypt(proPath),
				"']"
			})) != null;
		}

		public static void FormLogout(string proTitle, string proPath)
		{
			proTitle = CEncrypt.Encrypt(proTitle);
			proPath = CEncrypt.Encrypt(proPath);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlForm);
			foreach (object obj in xmlDocument.SelectNodes(string.Concat(new string[]
			{
				"Forms/Form[@Title='",
				proTitle,
				"'][@Path='",
				proPath,
				"']"
			})))
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode != null)
				{
					xmlNode.ParentNode.RemoveChild(xmlNode);
				}
			}
			XmlInfo.xmlForm = xmlDocument.InnerXml;
		}

		public static void SetCountSpec(List<string> listSpec)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCountSpec);
			XmlElement documentElement = xmlDocument.DocumentElement;
			foreach (string text in listSpec)
			{
				if (xmlDocument.SelectSingleNode("Elements/Spec[@Name='" + text + "']") == null)
				{
					XmlElement xmlElement = xmlDocument.CreateElement("Spec");
					xmlElement.SetAttribute("Name", text);
					xmlElement.SetAttribute("Check", "true");
					documentElement.InsertAfter(xmlElement, documentElement.LastChild);
				}
			}
			XmlInfo.xmlCountSpec = xmlDocument.InnerXml;
		}

		public static void ChangeFirstSpec(bool b)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCountSpec);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Elements/Spec");
			if (b)
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "true";
			}
			else
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "false";
			}
			XmlInfo.xmlCountSpec = xmlDocument.InnerXml;
		}

		public static void SetCountMater(List<string> listMater)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCountMater);
			XmlElement documentElement = xmlDocument.DocumentElement;
			foreach (string text in listMater)
			{
				if (xmlDocument.SelectSingleNode("Elements/Mater[@Name='" + text + "']") == null)
				{
					XmlElement xmlElement = xmlDocument.CreateElement("Mater");
					xmlElement.SetAttribute("Name", text);
					xmlElement.SetAttribute("Check", "true");
					documentElement.InsertAfter(xmlElement, documentElement.LastChild);
				}
			}
			XmlInfo.xmlCountMater = xmlDocument.InnerXml;
		}

		public static void ChangeFirstMater(bool b)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCountMater);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Elements/Mater");
			if (b)
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "true";
			}
			else
			{
				xmlNodeList.Item(0).Attributes["Check"].Value = "false";
			}
			XmlInfo.xmlCountMater = xmlDocument.InnerXml;
		}

		public static bool CountMaterIsCheck(string materName)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCountMater);
			return xmlDocument.SelectNodes("Elements/Mater[@Name='" + materName + "'][@Check='true']").Count > 0;
		}

		public static bool CountSpecIsCheck(string specName)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(XmlInfo.xmlCountSpec);
			return xmlDocument.SelectNodes("Elements/Spec[@Name='" + specName + "'][@Check='true']").Count > 0;
		}

		public static bool bShow = false;

		public static ExternalCommandData cmdDataModalForm = null;

		public static string currItem = "";

		public static string strLevel = "";

        public static Autodesk.Revit.DB.View View3D = null;

		public static string xmlThickness = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><WallTypes></WallTypes>";

		public static XmlDocument docWallParams = null;

		public static string xmlAttrVal = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements></Elements>";

		public static bool bFrmCreate = false;

		public static XmlDocument docSpaceType = null;

		public static XmlDocument docSpaceTypeTmp = null;

		public static XmlDocument docSpaceKeyword = null;

		public static XmlDocument docSpaceInfo = null;

		public static XmlDocument hyXmlDoc = new XmlDocument();

		public static string xmlSelSets = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><SelSets></SelSets>";

		public static string xmlStr1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements></Elements>";

		public static string xmlLevelStr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements></Elements>";

		public static string xmlCateStr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements><Cate Name=\"风管\" Check=\"false\"></Cate><Cate Name=\"风管管件\" Check=\"false\"></Cate><Cate Name=\"风口\" Check=\"false\"></Cate><Cate Name=\"风管阀件\" Check=\"false\"></Cate><Cate Name=\"水管\" Check=\"false\"></Cate><Cate Name=\"水管管件\" Check=\"false\"></Cate><Cate Name=\"水管阀件\" Check=\"false\"></Cate><Cate Name=\"墙\" Check=\"false\"></Cate><Cate Name=\"门\" Check=\"false\"></Cate><Cate Name=\"窗\" Check=\"false\"></Cate></Elements>";

		public static string xmlCountSel = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements></Elements>";

		public static string xmlCountResult = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements></Elements>";

		public static string xmlForm = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Forms><Form Title='标题' Path='路径'></Form></Forms>";

		public static string xmlCountSpec = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements><Spec Name=\"DN150\" Check=\"true\"></Spec><Spec Name=\"DE150\" Check=\"true\"></Spec></Elements>";

		public static string xmlCountMater = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Elements><Mater Name=\"铜\" Check=\"true\"></Mater><Mater Name=\"PVC-U\" Check=\"true\"></Mater></Elements>";
	}
}
